package com.finalcial.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.finalcial.dao.ApprovalDao;
import com.finalcial.dao.BasicDao;
import com.finalcial.dao.DetailedDao;
import com.finalcial.dao.OtherDao;
import com.finalcial.dao.PublicDao;
import com.finalcial.po.OtherInformation;
import com.finalcial.service.ApplicationService;

/**
 * 对应申请业务
 * @author Administrator
 *
 */
@Service
public  class ApplicationServiceImpl implements ApplicationService{

	@Autowired
	private PublicDao publicDao;//接受人下拉框
	@Autowired
	private OtherDao otherDao;//内部人明细
	@Autowired
	private BasicDao basicDao;//基本信息显示
	@Autowired
	private DetailedDao detailedDao;//申请表信息
	@Autowired
	private ApprovalDao approvalDao;//工作状态

	/**
	 * 申请报账中接收人下拉框接口(非管理员)
	 */
	@Override
	public List<Map<String, Object>> listUserNameAll(Integer roleId) {
		//进入界面显示接受人角色下拉框信息
		return publicDao.listUserNameAll(roleId);
	}

	/**
	 * 进入申请界面--显示接收者角色信息
	 */
	@Override
	public List<Map<String, Object>> showRoleNameList() {
		//进入界面显示接受人角色下拉框信息
		return publicDao.listRoleAll();
	}

	/**
	 * 进入申请界面--显示申请人基本信息
	 */
	@Override
	public List<Map<String, Object>> showBasicList(Integer userId) {
		return basicDao.getUserBasicInfo(userId);
	}


	/**
	 * 进入申请界面--显示预算指标信息
	 */
	@Override
	public String ShowBudgetIndicator(Integer reimbursementTypeId) {
		return basicDao.getBudgetIndicator(reimbursementTypeId);
	}


	/**
	 * 进入申请界面--显示票据类型名称信息
	 */
	@Override
	public List<Map<String, Object>> showInvoiceTypeName() {
		return basicDao.getInvoiceTypeName();
	}

	/**
	 * 进入申请界面--显示收款人信息
	 */
	@Override
	public OtherInformation showInsiderInfoOther(Integer userId) {
		return otherDao.getInsiderInfoOther(userId);
	}

	/**
	 * 申请差旅明细--查询记账成本中心
	 */
	@Override
	public String getUserDepartmentName(Integer userId) {
		return detailedDao.getUserDepartmentName(userId);
	}

	/**
	 * 员工福利申请界面--点击申请按钮新增数据
	 */
	@Override
	public Integer insertStaffApplicationMsg(Integer userId, Integer accepter, Integer invoiceTypeId,
			String reimbursementId, Date reimbursementTime, String reimbursementExplain, String payments,
			Date invoiceTime, String isAdvance, Integer reimbursementNumber, String isCostCapitalBudget,
			Integer reimbursementMoney, Integer reimbursementMoneyOfTax) {
		
	
		//新增收款表信息
		Integer state1 = basicDao.insertReceivables(userId, payments,reimbursementId);
		//新增报销表信息
		Integer reimbursementTypeId = 14004 ;//员工福利报销类型的id
		String isSingle = "";
		Integer state2 = basicDao.insertOPReimbursement(userId, reimbursementId, reimbursementTypeId, reimbursementTime, reimbursementNumber, reimbursementExplain, isAdvance, isSingle, reimbursementMoney, reimbursementMoneyOfTax, isCostCapitalBudget);
		//新增工作状态表信息
		String workStateName = "待办";
		Integer state3 = approvalDao.insertWorkStateByWork(reimbursementId, workStateName, accepter);
		Integer state = 0;
		if(state1!=0 && state2 != 0 && state3 != 0) {
			 state = 1;
		}else {
			state = 0;
		}
		//新增票据表信息
		return state;
	}
	
	/**
	 * 国内差旅申请界面--点击申请按钮新增数据
	 */
	@Override
	public Integer insertTravelApplicationMsg(Integer userId, String payments,
			String reimbursementId, Date reimbursementTime,
			String reimbursementExplain, Integer reimbursementNumber,
			Integer reimbursementMoney, Integer reimbursementMoneyOfTax,
			Integer accepterId) {
		
		//收款表
		Integer state1 = basicDao.insertReceivables(userId, payments, reimbursementId);
		//报销表
		 //国内差旅报销类型的id
		 Integer reimbursementTypeId = 14001;
		 //个人专项
		 String isSingle = "";
		 //资本/成本预算
		 String isCostCapitalBudget = "";
		 //员工垫付
		 String isAdvance = "";
		Integer state2 = basicDao.insertOPReimbursement(userId, reimbursementId, reimbursementTypeId, reimbursementTime, reimbursementNumber, reimbursementExplain, isAdvance, isSingle, reimbursementMoney, reimbursementMoneyOfTax, isCostCapitalBudget);
		//工作状态
		 //状态名
		 String workStateName = "待办";
		Integer state3 = approvalDao.insertWorkStateByWork(reimbursementId, workStateName, accepterId);
		Integer state = 0;
		if(state1!=0 && state2 != 0 && state3 != 0) {
			 state = 1;
		}else {
			state = 0;
		}
		return state;
	}
	
	/**
	 * 物业管理申请界面--点击申请按钮新增数据
	 */
	@Override
	public Integer insertManagerApplicationMsg(Integer userId,
			Integer accepter, Integer invoiceTypeId, String reimbursementId,
			Date reimbursementTime, String reimbursementExplain,
			String payments, Date invoiceTime, String isAdvance,
			Integer reimbursementNumber, String isCostCapitalBudget,
			Integer reimbursementMoney, Integer reimbursementMoneyOfTax,
			String isSingle) {
		
		//新增收款表信息
		Integer state1 = basicDao.insertReceivables(userId,  payments,reimbursementId);
		//新增报销表信息
		Integer reimbursementTypeId = 14003;//物业管理报销类型的id
		Integer state2 = basicDao.insertOPReimbursement(userId,  reimbursementId, reimbursementTypeId, reimbursementTime, reimbursementNumber,  reimbursementExplain, isAdvance, isSingle, reimbursementMoney,  reimbursementMoneyOfTax, isCostCapitalBudget);
		//新增工作状态表信息
		String workStateName = "待办";
		Integer state3 = approvalDao.insertWorkStateByWork(reimbursementId,  workStateName, accepter);
		Integer state = 0;
		if(state1!=0 && state2 != 0 && state3 != 0) {
			 state = 1;
		}else {
			state = 0;
		}
		return state;
	}
	/**
	 * 
	 * 公务交通申请界面--点击申请按钮新增数据
	 *
	 */
	@Override
	public Integer insertOffcialApplicationMsg(Integer userId, Integer accepterId, Integer invoiceTypeId,
			String reimbursementId, Date reimbursementTime, String reimbursementExplain, String payments,
			Date invoiceTime, String isAdvance, Integer reimbursementNumber, String isCostCapitalBudget,
			Integer reimbursementMoney, Integer reimbursementMoneyOfTax, String isSingle) {

		//新增收款表信息
		Integer state1 = basicDao.insertReceivables(userId,payments,reimbursementId);
		//新增报销表信息
		Integer reimbursementTypeId = 14002;//公务交通报销类型的id
		Integer state2 = basicDao.insertOPReimbursement(userId,reimbursementId, reimbursementTypeId, reimbursementTime, reimbursementNumber,  reimbursementExplain, isAdvance, isSingle, reimbursementMoney,  reimbursementMoneyOfTax, isCostCapitalBudget);
		//新增工作状态表信息
		String workStateName = "待办";
		Integer state3 = approvalDao.insertWorkStateByWork(reimbursementId, workStateName,accepterId);
		Integer state = 0;
		if(state1!=0 && state2 != 0 && state3 != 0) {
			 state = 1;
		}else {
			state = 0;
		}
		return state;
	}

	/**
	 * 
	 * 公务交通申请界面--根据用户ID查询报销金额上限
	 *
	 */
	@Override
	public List<Map<String, Object>> getFoodSalary(Integer userId) {
		// TODO Auto-generated method stub
		return detailedDao.getFoodSalary(userId);
	}

	@Override
	public Integer insertUploadAndMsg(String invoiceName, String invoiceTime, String reimbursementId,
			Integer invoiceTypeId, String enclosureUrl, String enclosureSize) {
		return detailedDao.insertUploadAndMsg(invoiceName, invoiceTime, reimbursementId,
				invoiceTypeId, enclosureUrl, enclosureSize);
	}

	/**
	 * 
	 * 国内差旅申请界面差旅明细--点击申请按钮新增数据
	 *
	 */
	@Override
	public Integer insertTravelDetailsApplication(Integer userId,
			String reimbursementId, Date businessTravelStartDate,
			Date businessTravelEndDate, String businessTravelStartSection,
			String businessTravelEndSection, String vehicleName,
			Integer foodCost, Integer cityTrafficExpense,
			Integer provinceTrafficExpense, Integer hotelExpense,
			Integer inputTax, Integer otherCost) {
		// TODO Auto-generated method stub
		return detailedDao.insertBusinessTravel(userId, reimbursementId, businessTravelStartDate, businessTravelEndDate, businessTravelStartSection, businessTravelEndSection, vehicleName, foodCost, cityTrafficExpense, provinceTrafficExpense, hotelExpense, inputTax, otherCost);
	}

	/**
	 * 申请报账中图片解析接口
	 * @param reimbursementId 报销id
	 * @return
	 */
	@Override
	public List<Map<String, Object>> getCheckSheet(String reimbursementId) {
		return publicDao.getCheckSheet(reimbursementId);
	}
	
	

}
